﻿@using Microsoft.AspNetCore.Mvc.ViewEngines
@inject ICompositeViewEngine Engine

@{
    //https://stackoverflow.com/a/18853875/1190512
    string returnUrl = ViewData.Eval("ReturnUrl").ToString();
    string appTitle = ViewData.Eval("AppTitle").ToString();
}
<header>
    <nav class="navbar navbar-expand-sm navbar-light navbar-toggleable-sm bg-white border-bottom box-shadow mb-3">
        <img class="header-image-img"
             src="~/icon.png"
             alt="STS" />
        <a class="nav-link text-dark" href="@returnUrl" title="Return to @appTitle">
            <i class="fas fa-home"></i>
            @appTitle
        </a>

        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
            @{
                var result = Engine.FindView(ViewContext, "_LoginPartial", isMainPage: false);
            }
            @if (result.Success)
            {
                await Html.RenderPartialAsync("_LoginPartial", returnUrl);
            }
            else
            {
                throw new InvalidOperationException("The default Identity UI layout requires a partial view '_LoginPartial' " +
                                                    "usually located at '/Pages/_LoginPartial' or at '/Views/Shared/_LoginPartial' to work. Based on your configuration " +
                                                    $"we have looked at it in the following locations: {System.Environment.NewLine}{string.Join(System.Environment.NewLine, result.SearchedLocations)}.");
            }

            <partial name="_SelectLanguagePartial"/>

        </div>
        
    </nav>
</header>